package com.jhgsys.internal.sypq.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.job.task.TestTask;
import com.jhgsys.internal.sypq.entity.Task;
import com.jhgsys.internal.sypq.entity.TaskTest;
import com.jhgsys.internal.sypq.service.ITaskTestService;
import com.wuwenze.poi.ExcelKit;
import jdk.nashorn.internal.ir.RuntimeNode;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * 试验内容 Controller
 *
 * @author ganjun
 * @date 2024-11-18 11:13:09
 */
@Slf4j
@Validated
@Controller
public class TaskTestController extends BaseController {

    @Autowired
    private ITaskTestService taskTestService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "taskTest")
    public String taskTestIndex(){
        return jumpPage("sypq/taskTest/taskTestList");
    }



    @GetMapping(FebsConstant.VIEW_PREFIX + "taskTest/row")
    public String taskTestAdd1(Model model,@RequestParam("id")Integer id,@RequestParam("no")Integer no,
      @RequestParam("resistance")String resistance,  @RequestParam("navigate")String navigate,
        @RequestParam("seakeep")String seakeep,@RequestParam("controll")String controll,
                               @RequestParam("vain")String vain){
        TaskTest taskTest=new TaskTest();
        taskTest.setId(id);
        taskTest.setNo(no);
        taskTest.setResistance(resistance);
        taskTest.setNavigate(navigate);
        taskTest.setSeakeep(seakeep);
        taskTest.setControll(controll);
        taskTest.setVain(vain);
        model.addAttribute("taskTest",taskTest);
        return jumpPage("sypq/taskTest/taskTestEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "taskTest/update/{id}")
    public String taskTestUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("taskTest", taskTestService.findTaskTestById(id));
        return jumpPage("sypq/taskTest/taskTestEdit");
    }

    /**
     * 查询（所有）
     * @author ganjun
     * @date 2024-11-18 11:13:09
     */
    @GetMapping("taskTest")
    @ResponseBody
    public FebsResponse getAllTaskTests(TaskTest taskTest) {
        try {
            return success(taskTestService.findTaskTestList(taskTest));
        }catch (Exception ex){
            return failure(ex);
        }

    }

    /**
     * 查询（分页）
     * @author ganjun
     * @date 2024-11-18 11:13:09
     */
    @GetMapping("taskTest/list")
    @ResponseBody
    public FebsResponse taskTestList(QueryRequest request, TaskTest taskTest) {
        try {
            Map<String, Object> dataTable = getDataTable(this.taskTestService.findTaskTestPage(request, taskTest));
            return success(dataTable);
        }catch (Exception ex){
            return failure(ex);
        }
    }

    /**
     * 新增 TaskTest
     * @author ganjun
     * @date 2024-11-18 11:13:09
     */
    @Log("新增TaskTest")
    @PostMapping("taskTest")
    @ResponseBody
    public FebsResponse addTaskTest(@Valid TaskTest taskTest) throws FebsException {
        try {
            this.taskTestService.createTaskTest(taskTest);
            return success();
        } catch (Exception ex) {
            return failure(ex,"新增失败");
        }
    }

    /**
     * 逻辑删除 TaskTest
     * @author ganjun
     * @date 2024-11-18 11:13:09
     */
    @Log("逻辑删除TaskTest")
    @GetMapping("taskTest/delete/{id}")
    @ResponseBody
    public FebsResponse deleteTaskTest(@PathVariable("id") String taskTestIds) throws FebsException {
        try {
            TaskTest taskTest = new TaskTest();
            taskTest.setDeletedBy(getCurrentUser().getUserName());
            taskTest.setDeletedTime(new Date());
            taskTest.setDeletedFlg(FebsConstant.INVALID);
            this.taskTestService.deleteTaskTest(taskTest,taskTestIds);
            return success();
        } catch (Exception ex) {
            return failure(ex,"删除失败");
        }
    }

    /**
    * 物理删除 TaskTest
    * @author ganjun
    * @date 2024-11-18 11:13:09
    */
    @Log("物理删除TaskTest")
    @GetMapping("taskTest/physicallyDelete/{id}")
    @ResponseBody
    public FebsResponse physicallyDeleteTaskTest(@PathVariable("id") String taskTestIds) throws FebsException {
        try {
            this.taskTestService.physicallyDeleteTaskTest(taskTestIds);
            return success();
        } catch (Exception ex) {
            return failure(ex,"删除失败");
        }
    }

    /**
     * 修改 TaskTest
     * @author ganjun
     * @date 2024-11-18 11:13:09
     */
    @Log("修改TaskTest")
    @PostMapping("taskTest/update")
    @ResponseBody
    public FebsResponse updateTaskTest(TaskTest taskTest) throws FebsException {
        try {
            this.taskTestService.updateTaskTest(taskTest);
            return success();
        } catch (Exception ex) {
            return failure(ex,"修改失败");
        }
    }

}
